package com.ssb.plugins;

import com.apache.cache.util.Validator;
import com.apache.database.model.Page;
import com.apache.ius.plugin.CustomMethodPlugin;
import com.apache.ius.plugin.IusPluginUtil;

import java.util.Map;

/**
 * @Classname SelectOrderStatisticalPluginImpl
 * @Description 查询统计报表 以保单为主
 * @Date 2020/2/19 22:55
 * @Created by fpc
 */
public class SelectOrderStatisticalPluginImpl implements CustomMethodPlugin {
    @Override
    public Object beforeInvoke(Map<String, Object> param) {
        String pageNo = Validator.getDefaultStr(String.valueOf(param.get("page")),"1");
        String rows = Validator.getDefaultStr(String.valueOf(param.get("rows")),"10");
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT sio.create_user as create_user,");
        sb.append("sio.create_time as create_time,");
        sb.append("sio.request_no as request_no,");
        sb.append("sio.policy_no as policy_no,");
        sb.append("sip.insur_code as insur_code,");
        sb.append("sip.agent_risk_cname as agent_risk_cname,");
        sb.append("sio.amount as amount,");
        sb.append("sio.premium as premium ");
        sb.append("FROM ss_insur_order sio LEFT JOIN ss_insur_pro sip ON sio.pro_code=sip.pro_code  WHERE 1=1 ");
        String agentRiskCname = String.valueOf(param.get("ssInsurOrder.wl_agentRiskCname"));
        if(Validator.isNotNull(agentRiskCname)){
            sb.append(" AND sip.agent_risk_cname like '%"+agentRiskCname+"%' ");
        }
        String createTimeStart = String.valueOf(param.get("ssInsurOrder.createTimeStart"));
        if(Validator.isNotNull(createTimeStart)){
            sb.append(" AND sio.create_time >='"+createTimeStart+" 00:00:00'");
        }
        String createTimeEnd = String.valueOf(param.get("ssInsurOrder.createTimeEnd"));
        if(Validator.isNotNull(createTimeEnd)){
            sb.append(" AND sio.create_time <='"+createTimeEnd+" 23:59:59'");
        }
        sb.append(" order by sio.create_time");
        Object objEntity = IusPluginUtil.getInstance().select(sb.toString(), Integer.parseInt(pageNo), Integer.parseInt(rows));
        param.put(CustomMethodPlugin.pluginInnerReturn, objEntity);
        param.put(CustomMethodPlugin.resultMark, "T");
        return null;
    }

    @Override
    public Object doInvoke(Map<String, Object> param) {
        return null;
    }

    @Override
    public Object afterInvoke(Map<String, Object> param) {
        return null;
    }
}
